﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JzSport.Model
{
    public class JzSportDbContext : DbContext
    {
        static JzSportDbContext()
        {
            Database.SetInitializer<JzSportDbContext>(null);
        }

        public JzSportDbContext()
            : base("name=jzsport-db")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Account>().ToTable("Account");
            modelBuilder.Entity<Account>().HasKey(p=>p.Id);
            modelBuilder.Entity<Account>().Property(p => p.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            modelBuilder.Entity<IllegalPasswordRecord>().ToTable("IllegalPasswordRecord");
            modelBuilder.Entity<IllegalPasswordRecord>().HasKey(p => p.Id);

            modelBuilder.Entity<Config>().ToTable("Config");
            modelBuilder.Entity<Config>().HasKey(p => p.Code);

            modelBuilder.Entity<Data.MessageView>().ToTable("MessageView");

            modelBuilder.Entity<Message>().ToTable("Message");
            modelBuilder.Entity<Message>().HasKey(p => p.Id);

            modelBuilder.Entity<MessageClip>().ToTable("MessageClip");
            modelBuilder.Entity<MessageClip>().HasKey(p => p.Id);
       
            modelBuilder.Entity<Verifycode>().ToTable("Verifycode");
            modelBuilder.Entity<Verifycode>().HasKey(p => p.Id);

            modelBuilder.Entity<Activity>().ToTable("Activity");
            modelBuilder.Entity<Activity>().HasKey(p => p.Id);

            modelBuilder.Entity<ActivityImage>().ToTable("ActivityImage");
            modelBuilder.Entity<ActivityImage>().HasKey(p => p.Id);

            modelBuilder.Entity<ActivityMember>().ToTable("ActivityMember");
            modelBuilder.Entity<ActivityMember>().HasKey(p => p.Id);

            modelBuilder.Entity<ActivityJoinRequest>().ToTable("ActivityJoinRequest");
            modelBuilder.Entity<ActivityJoinRequest>().HasKey(p => new { p.ActivityId, p.UserId });

            modelBuilder.Entity<ActivityFeedback>().ToTable("ActivityFeedback");
            modelBuilder.Entity<ActivityFeedback>().HasKey(p => p.Id);

            modelBuilder.Entity<ImageResource>().ToTable("ImageResource");
            modelBuilder.Entity<ImageResource>().HasKey(p => p.Id);

            modelBuilder.Entity<UserRelation>().ToTable("UserRelation");
            modelBuilder.Entity<UserRelation>().HasKey(p => p.Id);


            modelBuilder.Entity<BaseDataSummary>().ToTable("BaseDataSummary");
            modelBuilder.Entity<BaseDataSummary>().HasKey(p => p.Id);
            modelBuilder.Entity<BaseDataItem>().ToTable("BaseDataItem");
            modelBuilder.Entity<BaseDataItem>().HasKey(p => p.Id);

            //do something
            base.OnModelCreating(modelBuilder);
        }
    }
}
